package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021/7/12.<br><br>
 *
 * Excel列表名称
 */
public class Topic168 {

    public static void main(String[] args) {
        Topic168 instance = new Topic168();

        System.out.println(instance.convertToTitle(1));
        System.out.println(instance.convertToTitle(28));
        System.out.println(instance.convertToTitle(701));
        System.out.println(instance.convertToTitle(2147483647));
    }

    public String convertToTitle(int columnNumber) {
        StringBuilder result = new StringBuilder();

        while (columnNumber != 0) {
            result.insert(0, (char)('A' + (columnNumber - 1) % 26));
            columnNumber = (columnNumber - 1) / 26;
        }

        return result.toString();
    }
}
